package com.itheima.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.Enumeration;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class JedisUtils {

    private static JedisPool jp;
    private static String host;
    private static int port;
    private static int MaxTotal;
    private static int MaxIdle;
    private static JedisPoolConfig poolConfig;
    static {
        ResourceBundle rb=ResourceBundle.getBundle("redis");
         host = rb.getString("redis.host");
         port = Integer.parseInt(rb.getString("redis.port"));
         MaxTotal = Integer.parseInt(rb.getString("redis.setMaxTotal"));
         MaxIdle = Integer.parseInt( rb.getString("redis.setMaxIdle"));
         poolConfig= new JedisPoolConfig();
         poolConfig.setMaxTotal(MaxTotal);
         poolConfig.setMaxIdle(MaxIdle);
        jp=new JedisPool(poolConfig,"localhost",6379);
    }

    public static Jedis getJedis(){
        return jp.getResource();
    }
}
